// 定义${entity.moduleUpperFirstChar}${entity.entityName}Grid类的构造函数
var ${entity.moduleUpperFirstChar}${entity.entityName}Grid = function (cfg) {

    // 为了在任何情况下可以获得${entity.moduleUpperFirstChar}${entity.entityName}Grid的实例对象
    var me = this;

    // 调用父类构造函数
    ${entity.moduleUpperFirstChar}${entity.entityName}Grid.superclass.constructor.call(this, Ext.apply({
        url: '${entity.module}/${entity.entityNameLowerFirstChar}/list',
        woIdProperty: '${entity.keys.get(0).fieldName}',
        woNameProperty: '${entity.columns.get(0).fieldName}',
        woTitle: '${entity.entityCN}列表',
        singleSelect: false,
        woPaging : true,
        woColumns: [
        #foreach ($col in $entity.keys)
        #if($velocityHasNext) , #end
        {
            header: '${col.fieldCN}',
            dataIndex: '${col.fieldName}',
            hidden: true,
            width: 150
        }
        #end
        #foreach ($col in $entity.columns)
        ,{
            header: '${col.fieldCN}',
            dataIndex: '${col.fieldName}',
            hidden: false,
            width: 150
        }
        #end
        #foreach ($r in $entity.relationsM21)
        , {
            header: '${r.sourceFieldCN}ID',
            dataIndex: '${r.sourceFieldName}${r.target.keys.get(0).fieldNameUpperFirstChar}',
            hidden: true,
            width: 150
        }, {
            header: '${r.sourceFieldCN}',
            dataIndex: '${r.sourceFieldName}${r.target.columns.get(0).fieldNameUpperFirstChar}',
            hidden: false,
            width: 150
        }
        #end
        #foreach ($r in $entity.relationsM2M)
        , {
            header: '${r.sourceFieldCN}ID',
            dataIndex: '${r.sourceFieldName}${r.target.keys.get(0).fieldNameUpperFirstChar}',
            hidden: true,
            width: 150
        }, {
            header: '${r.sourceFieldCN}',
            dataIndex: '${r.sourceFieldName}${r.target.columns.get(0).fieldNameUpperFirstChar}',
            hidden: false,
            width: 150
        }
        #end
        ],
        woButtons: [{
            woButtonType: 'wo.list.create', // 创建按钮
            woForm: ${entity.moduleUpperFirstChar}${entity.entityName}CreateForm, // 创建表单类
            woGridSelectType: 'singleornone' // 设置列表选择类型：单选或者不选
        }, {
            woButtonType: 'wo.list.delete', // 删除按钮
            woGridSelectType: 'single', // 设置列表选择类型：单选
            woUrl: '${entity.module}/${entity.entityNameLowerFirstChar}/delete' // 设置删除提交url，key值为selectedIds
        }],
        // 查询字段
        woSearchFields: [{
            items: [{
                name: 'searchContent',
                fieldLabel: '查询内容',
                width: 100
            }]
        }],
        woUpdateForm: ${entity.moduleUpperFirstChar}${entity.entityName}UpdateForm // 设置列表双击时，弹出的修改表单类
    }, cfg));
};
// ${entity.moduleUpperFirstChar}${entity.entityName}Grid继承Wo.GridPanel
Ext.extend(${entity.moduleUpperFirstChar}${entity.entityName}Grid, Wo.GridPanel, {});

#foreach ($r in $entity.relationsM2M)
Wo.loadJsByClass('${r.target.moduleUpperFirstChar}${r.target.entityName}Grid');
#end
#foreach ($r in $entity.relationsM21)
Wo.loadJsByClass('${r.target.moduleUpperFirstChar}${r.target.entityName}Grid');
#end

// 定义${entity.entityCN}的创建表单，继承Wo.FormPanel
var ${entity.moduleUpperFirstChar}${entity.entityName}CreateForm = function (cfg) {
    // 调用父类构造函数
    ${entity.moduleUpperFirstChar}${entity.entityName}CreateForm.superclass.constructor.call(this, Ext.apply({
        columns: 1,
        url: '${entity.module}/${entity.entityNameLowerFirstChar}/create',
        title: '创建${entity.entityCN}',
        width: 400,
        height: 300,
        items: [
    	#foreach ($col in $entity.keys)
        #if($velocityHasNext) , #end
        {
            items: [{
                name: '${col.fieldName}',
                fieldLabel: '${col.fieldCN}',
                #if (${col.fieldType.name} == "java.util.Date")
                xtype : 'xdatetime',
                #end
                allowBlank: ${col.nullable},
                width: 200
            }]
        }
        #end
        #foreach ($col in $entity.columns)
        , {
            items: [{
                name: '${col.fieldName}',
                fieldLabel: '${col.fieldCN}',
                allowBlank: ${col.nullable},
                #if (${col.fieldType.name} == "java.util.Date")
                xtype : 'xdatetime',
                #end
                width: 200
            }]
        }
        #end
        #foreach ($r in $entity.relationsM21)
        , {
            items: [{
                xtype: 'objectsearch', // 控件类型设置为对象查找
                hiddenName: '${r.sourceFieldName}${r.target.keys.get(0).fieldNameUpperFirstChar}', // ${r.sourceFieldCN}id
                name: '${r.sourceFieldName}${r.target.columns.get(0).fieldNameUpperFirstChar}', // ${r.sourceFieldCN}名称
                fieldLabel: '${r.sourceFieldCN}',
                #if (${r.relateSelf()})
                value: cfg.gridSelectedIds, // 设置列表上选中的${entity.entityCN}ID作为上级${entity.entityCN}ID
                woText: cfg.gridSelectedNames, // 设置列表上选中的${entity.entityCN}名称作为上级${entity.entityCN}名称
                #end
                woPanelClass: '${r.target.moduleUpperFirstChar}${r.target.entityName}Grid', // 弹出grid的类
                width: 200
            }]
        }
        #end
        #foreach ($r in $entity.relationsM2M)
        , {
            items: [{
                xtype: 'objectsearch', // 控件类型设置为对象查找
                hiddenName: '${r.sourceFieldName}${r.target.keys.get(0).fieldNameUpperFirstChar}', // ${r.sourceFieldCN}id
                name: '${r.sourceFieldName}${r.target.columns.get(0).fieldNameUpperFirstChar}', // ${r.sourceFieldCN}名称
                fieldLabel: '${r.sourceFieldCN}',
                selectLength : -1, // 设置多选
                woPanelClass: '${r.target.moduleUpperFirstChar}${r.target.entityName}Grid', // 弹出grid的类
                width: 200
            }]
        }
        #end
        ]
    }, cfg));
};
// 继承
Ext.extend(${entity.moduleUpperFirstChar}${entity.entityName}CreateForm, Wo.FormPanel, {});

// 定义${entity.entityCN}修改表单
var ${entity.moduleUpperFirstChar}${entity.entityName}UpdateForm = function (cfg) {
    ${entity.moduleUpperFirstChar}${entity.entityName}UpdateForm.superclass.constructor.call(this, Ext.apply({
        columns: 1,
        url: '${entity.module}/${entity.entityNameLowerFirstChar}/update',
        title: '修改${entity.entityCN}',
        width: 400,
        height: 300,
        items: [
    	#foreach ($col in $entity.keys)
        #if($velocityHasNext) , #end
        {
            items: [{
                name: '${col.fieldName}',
                fieldLabel: '${col.fieldCN}',
                width: 200,
                readOnly: true,
                value: cfg.row.get('${col.fieldName}')
            }]
        }
    	#end
    	#foreach ($col in $entity.columns)
        , {
            items: [{
                name: '${col.fieldName}',
                fieldLabel: '${col.fieldCN}',
                width: 200,
                #if (${col.fieldType.name} == "java.util.Date")
                xtype : 'xdatetime',
                #end
                allowBlank: ${col.nullable},
                value: cfg.row.get('${col.fieldName}')
            }]
        }
    	#end
    	#foreach ($r in $entity.relationsM21)
    	, {
            items: [{
                xtype: 'objectsearch',
                hiddenName: '${r.sourceFieldName}${r.target.keys.get(0).fieldNameUpperFirstChar}',
                name: '${r.sourceFieldName}${r.target.columns.get(0).fieldNameUpperFirstChar}',
                fieldLabel: '${r.sourceFieldCN}',
                width: 200,
                value: cfg.row.get('${r.sourceFieldName}${r.target.keys.get(0).fieldNameUpperFirstChar}'), // hiddenName对应的值
                woText: cfg.row.get('${r.sourceFieldName}${r.target.columns.get(0).fieldNameUpperFirstChar}'), // name对应的值
                woPanelClass: '${r.target.moduleUpperFirstChar}${r.target.entityName}Grid', // 弹出grid的类
                width: 200
            }]
        }
    	#end
    	#foreach ($r in $entity.relationsM2M)
        , {
            items: [{
                xtype: 'objectsearch', // 控件类型设置为对象查找
                hiddenName: '${r.sourceFieldName}${r.target.keys.get(0).fieldNameUpperFirstChar}', // ${r.sourceFieldCN}id
                name: '${r.sourceFieldName}${r.target.columns.get(0).fieldNameUpperFirstChar}', // ${r.sourceFieldCN}名称
                fieldLabel: '${r.sourceFieldCN}',
                value: cfg.row.get('${r.sourceFieldName}${r.target.keys.get(0).fieldNameUpperFirstChar}'),
                woText: cfg.row.get('${r.sourceFieldName}${r.target.columns.get(0).fieldNameUpperFirstChar}'),
                selectLength : -1, // 设置多选
                woPanelClass: '${r.target.moduleUpperFirstChar}${r.target.entityName}Grid', // 弹出grid的类
                width: 200
            }]
        }
        #end
    	]
    }, cfg));
};
Ext.extend(${entity.moduleUpperFirstChar}${entity.entityName}UpdateForm, Wo.FormPanel, {});